package servlet.search;

import com.alibaba.fastjson.JSON;
import pojo.Page;
import service.SearchIndexpagere;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/searchbookpage")
public class SearchBookPage extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应对象类型
        resp.setContentType("application/json;charset=utf-8");
        // 从请求中获取参数
        String name = req.getParameter("input"); // 获取图书分类名称
        SearchIndexpagere searchIndexpagere = new SearchIndexpagere();
        Page page1 = searchIndexpagere.selectBookPage(name);
        String jsonString = JSON.toJSONString(page1);
        PrintWriter writer = resp.getWriter();
        writer.write(jsonString);
    }
}
